<template>
    <view class="dividend_outer">
        <view class="dividend_outer_box">
            <view class="dividend_header">
                <view class="dividend_header_box">
                    <view class="dividend_header_back" @click="GoBack">
                        <image src="@/static/dividend/back.png"></image>
                    </view>
                    <view class="dividend_header_title">分红明细</view>
                </view>
            </view>
            <view class="reward_tabs">
                <circleTabs v-model="tabIndex" :tabList="list" mode="skew"></circleTabs>
            </view>
        </view>
        <scroll-view :scroll-y="true" class="record_list" :style="{ height: rewardRecordListHeight + 'rpx' }"
            @scrolltolower="refreshList">
            <view class="record_item" v-for="item, index in DividendList" :key="index">
                <view class="record_item_left">
                    <view class="record_item_left_top"><text>{{ item.userId }}</text></view>
                    <view class="record_item_left_down"><text>{{ item.date }}</text></view>
                </view>
                <view class="record_item_right" v-if="tabIndex == 0">
                    <text class="add" v-if="item.num > 0">+{{ Math.floor(item.num) / 1000 }}K</text>
                    <text class="subtract" v-else>{{ Math.floor(item.num) / 1000 }}K</text>
                </view>
                <view class="record_item_right" v-if="tabIndex == 1">
                    <text class="add" v-if="item.num > 0">+{{ item.num.toFixed(5) }}</text>
                    <text class="subtract" v-else>{{ item.num.toFixed(5) }}</text>
                </view>
            </view>
        </scroll-view>
    </view>
</template>

<script>
import { reqDividendList } from '@/api/dividend.js'
import circleTabs from "@/components/circle-tabs/circle-tabs.vue";

export default {
    data() {
        return {
            // 钻石手续费奖励与云豆手续费奖励切换
            tabIndex: 0,
            // 转赠与转赠列表list
            list: [
                {
                    id: 0,
                    title: "钻石手续费奖励",
                },
                {
                    id: 1,
                    title: "云豆手续费奖励",
                },
            ],
            rewardRecordListHeight: 0,
            pageNum: 1,
            DividendList: [],
            DividendListTotal: 0
        }
    },
    onLoad() {
        this.getDividendList()
        this.computedHeight()
    },
    methods: {
        GoBack() {
            uni.switchTab({
                url: "/pages/my/index",
            });
        },
        async getDividendList(val) {
            const sendData = {
                pageNum: this.pageNum,
                pageSize: 10,
                currencyId: this.tabIndex == 0 ? 3 : 1
            }
            const result = await reqDividendList(sendData)
            if (result.code == 200) {
                if (val != 1) {
                    this.DividendList = result.data.list
                } else {
                    this.DividendList = this.DividendList.concat(result.data.list);
                }
                this.DividendListTotal = result.data.total
            } else {
                uni.showToast({
                    title: result.msg,
                    icon: "error",
                });
            }
        },
        // 到底后刷新列表
        refreshList() {
            if (this.DividendList.length >= this.DividendListTotal) {
                uni.showToast({
                    title: "没有更多了",
                    icon: "error",
                });
            } else {
                this.pageNum++;
                this.getDividendList(1);
            }
        },
        computedHeight() {
            uni.getSystemInfo({
                success: (res) => {
                    const screenHeight = res.windowHeight; // 屏幕高度，单位为px
                    this.rewardRecordListHeight = this.$pxToRpx(screenHeight) - 320;
                },
            });
        },
    },
    watch: {
        tabIndex(val) {
            this.pageNum = 1
            this.getDividendList()

        },
    },
    components: {
        circleTabs
    }
}
</script>

<style lang="scss" scoped>
.dividend_outer {
    width: 100vw;
    height: 100vh;
    background: #FFFAEF;

    .dividend_outer_box {
        height: 320rpx;
    }

    .dividend_header {
        width: 750rpx;
        height: 301rpx;
        background: linear-gradient(180deg, #FF811B 0%, #FFA748 100%);
        border-radius: 0rpx 0rpx 0rpx 0rpx;
        opacity: 1;

        .dividend_header_box {
            width: 100%;
            display: flex;
            align-items: center;
            padding-top: 74rpx;
            position: relative;
        }

        .dividend_header_back {
            width: 46rpx;
            height: 46rpx;
            margin-left: 44rpx;

            image {
                width: 100%;
                height: 100%;
            }
        }

        .dividend_header_title {
            margin: 0 auto;
            padding-right: 90rpx;
            font-size: 46rpx;
            font-family: Inter, Inter;
            font-weight: 600;
            color: #FFFFFF;
        }

    }

    .reward_tabs {
        margin-top: -80rpx;
    }

    .record_list {
        width: 100vw;

        .record_item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 2rpx solid rgb(183, 178, 169, 0.35);
            padding: 42rpx 0;

            .record_item_left {
                margin-left: 44rpx;
                display: flex;
                flex-direction: column;
                row-gap: 16rpx;

                .record_item_left_top {
                    font-size: 29rpx;
                    font-family: Inter, Inter;
                    font-weight: 500;
                    color: #302B26;
                }

                .record_item_left_down {
                    font-size: 26rpx;
                    font-family: Inter, Inter;
                    font-weight: 400;
                    color: #6C6862;


                }
            }

            .record_item_right {
                margin-right: 44rpx;

                .add {
                    font-size: 38rpx;
                    font-family: Inter, Inter;
                    font-weight: 600;
                    color: #FC4100;
                }

                .subtract {
                    font-size: 38rpx;
                    font-family: Inter, Inter;
                    font-weight: 600;
                    color: #000000;
                }
            }
        }
    }
}
</style>